﻿using B.S.DataBase.SuY.Read.Api.AutoList.Command;
using B.S.DataBase.SuYuan.Domain.Model;
using B.S.DataBase.SuYuan.ErrorCode;
using B.S.DataBase.SuYuan.Infrastructrue.Interface;
using MediatR;

namespace B.S.DataBase.SuY.Read.Api.AutoList.CommandHarder
{
    public class DelGoodesCommandHarder : IRequestHandler<DelGoodesCommand, ApiReslit<object>>
    {

        private readonly IBaseRepository<Goods> repository;

        public DelGoodesCommandHarder(IBaseRepository<Goods> repository)
        {
            this.repository = repository;
        }

        public Task<ApiReslit<object>> Handle(DelGoodesCommand request, CancellationToken cancellationToken)
        {
            ApiReslit<object> reslit = new ApiReslit<object>();
            reslit.Code= ApiEnum.删除成功;
            reslit.Msg = ApiEnum.删除成功.ToString();

            var xi = repository.GetAll().Result.Where(x => x.G_Id == request.G_Id).FirstOrDefault();
            repository.Delete(xi);

            return Task.FromResult(reslit);
        }
    }
}
